#
# @lc app=leetcode.cn id=198 lang=python
#
# [198] 打家劫舍
#

# @lc code=start
class Solution(object):
    def rob(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) == 1:
            return nums[0]
        if len(nums) == 2:
            return max(nums[0], nums[1])

        dp = [0] * 3
        dp[0] = nums[0]
        dp[1] = nums[1]
        dp[2] = nums[0]+nums[2]
        for i in range(3, len(nums)):
            temp0 = max(dp[0], dp[1])+nums[i]
            dp[0] = dp[1]
            dp[1] = dp[2]
            dp[2] = temp0
        return max(dp[1], dp[2])

        
# @lc code=end

